﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERPStore.Coupons.EventConsumers
{
	public class AddCouponToCartEventConsumer : EventBrokR.IConsumer<ERPStore.Web.Events.AddCouponToCart>
	{
		public AddCouponToCartEventConsumer (Services.AdminIncentiveService admin)
		{
			this.AdminIncentiveService = admin;
		}

		protected Services.AdminIncentiveService AdminIncentiveService { get; private set; }

		public void Handle(ERPStore.Web.Events.AddCouponToCart @event)
		{
			var coupon = AdminIncentiveService.GetCouponByCode(@event.CouponCode);
			coupon.UsedCount++;
			AdminIncentiveService.SaveCoupon(coupon);
		}
	}
}
